import {getQuery} from "../../utils/databaseUtil";

export async function getProductImage(designId) {
    var getProductImage_q = new AV.Query('productImages')
    var desing_av = AV.Object.createWithoutData('design', designId);
    getProductImage_q.equalTo('design', desing_av)
    getProductImage_q.include('design')
    var result = await getProductImage_q.first()
    if (!result) {
        return null
    }
    var one = result.toJSON()
    var files = []
    var query = new AV.Query('_File');
    for (var i = 0; i < one.files.length; i++) {
        var file_Object_id = one.files[i]
        var _file = await  query.get(file_Object_id)
        files.push(_file.toJSON())
    }
    one.files = files
    return one
}

export async function get_design(designId) {
    var q = getQuery('design')
    var result = await q.equalTo('objectId', designId).first().then(res => res.toJSON())
    return result

}